<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>活动抽奖</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <style>
        /* =========  基础变量  ========= */
        :root {
            --bg0: #0f0c1f;
            --bg1: #1a1142;
            --neonC: #00f9ff;
            --neonM: #ff00a0;
            --glass: rgba(255,255,255,.08);
            --radius: 16px;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif
        }

        body {
            min-height: 100vh;
            background: linear-gradient(135deg,var(--bg0),var(--bg1));
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            overflow-x: hidden;
        }

        .container {
            max-width: 800px;
            width: 100%;
            text-align: center;
            animation: fadeIn .6s
        }

        /* =========  标题  ========= */
        h1 {
            font-size: 2.6rem;
            letter-spacing: 2px;
            margin-bottom: .5em;
            background: linear-gradient(90deg,var(--neonC),var(--neonM));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            filter: drop-shadow(0 0 6px var(--neonC));
        }

        /* =========  九宫格  ========= */
        .grid-container {
            display: grid;
            grid-template-columns: repeat(3,1fr);
            gap: 18px;
            max-width: 480px;
            margin: 30px auto;
            padding: 20px;
            background: var(--glass);
            border-radius: var(--radius);
            backdrop-filter: blur(12px);
            border: 1px solid var(--neonC);
            box-shadow: 0 0 25px var(--neonC);
        }

        .grid-item {
            aspect-ratio: 1/1;
            background: var(--glass);
            border: 1px solid var(--neonC);
            border-radius: var(--radius);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            transition: .3s;
            position: relative;
            overflow: hidden;
        }

            .grid-item::before {
                content: '';
                position: absolute;
                inset: 0;
                background: linear-gradient(45deg,transparent,rgba(0,249,255,.15),transparent);
                opacity: 0;
                transition: .3s;
            }

            .grid-item.active {
                background: rgba(0,249,255,.25);
                transform: scale(1.08)
            }

            .grid-item.win {
                animation: pulse 1s infinite
            }

        @keyframes pulse {
            0%,100% {
                box-shadow: 0 0 10px var(--neonC)
            }

            50% {
                box-shadow: 0 0 30px var(--neonC),0 0 50px var(--neonM)
            }
        }

        .prize-icon {
            font-size: 2.8rem;
            margin-bottom: 6px
        }

        .prize-name {
            font-size: 1rem;
            font-weight: 600
        }

        .prize-value {
            font-size: .8rem;
            opacity: .7
        }

        /* =========  按钮  ========= */
        .button-container {
            display: flex;
            justify-content: center;
            gap: 20px;
            flex-wrap: wrap;
            margin: 25px 0;
        }

        .btn {
            padding: 14px 32px;
            font-size: 1rem;
            font-weight: 700;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: .3s;
            color: #fff;
            position: relative;
            overflow: hidden;
        }

            .btn:disabled {
                opacity: .4;
                cursor: not-allowed
            }

        .btn-start {
            background: linear-gradient(45deg,#00c853,#00ffa2)
        }

        .btn-stop {
            background: linear-gradient(45deg,#ff5252,#ff4081)
        }

        .btn-reset {
            background: linear-gradient(45deg,#2196f3,#21cbf3)
        }

        .btn:hover:not(:disabled) {
            transform: translateY(-4px);
            filter: brightness(1.2)
        }

        /* =========  结果卡片  ========= */
        .result-container, .speed-control, .history {
            background: var(--glass);
            border: 1px solid var(--neonC);
            border-radius: var(--radius);
            padding: 20px;
            margin: 20px auto;
            max-width: 480px;
            backdrop-filter: blur(12px);
        }

        .result-title {
            color: var(--neonC);
            font-size: 1.4rem;
            margin-bottom: 10px
        }

        .result-icon {
            font-size: 3.2rem;
            margin-bottom: 10px;
            animation: float 2s infinite alternate
        }

        @keyframes float {
            from {
                transform: translateY(0)
            }

            to {
                transform: translateY(-8px)
            }
        }

        /* =========  速度滑条  ========= */
        .slider-container {
            display: flex;
            align-items: center;
            gap: 10px
        }

        input[type=range] {
            flex: 1;
            -webkit-appearance: none;
            height: 6px;
            border-radius: 3px;
            background: var(--glass);
            outline: none
        }

            input[type=range]::-webkit-slider-thumb {
                -webkit-appearance: none;
                width: 18px;
                height: 18px;
                border-radius: 50%;
                background: var(--neonM);
                cursor: pointer
            }

        /* =========  抽奖记录（水平居中） ========= */
        .history h2 {
            color: var(--neonM);
            margin-bottom: 12px;
            font-size: 1.4rem
        }

        .history-list {
            display: flex;
            justify-content: center;
            gap: 12px;
            overflow-x: auto;
            padding-bottom: 6px;
        }

        .history-item {
            flex: 0 0 140px;
            background: var(--glass);
            border: 1px solid var(--neonM);
            border-radius: var(--radius);
            padding: 12px;
            display: flex;
            flex-direction: column;
            align-items: center;
            font-size: .85rem;
            min-width: 120px;
        }

        .history-icon {
            font-size: 1.8rem;
            margin-bottom: 6px
        }

        .history-name {
            font-weight: 600;
            margin-bottom: 4px
        }

        .history-time {
            opacity: .6;
            font-size: .75rem
        }

        /* =========  彩色纸屑（简化）  ========= */
        .confetti {
            position: fixed;
            width: 8px;
            height: 8px;
            top: -10px;
            border-radius: 50%;
            animation: fall 3s linear forwards;
        }

        @keyframes fall {
            to {
                transform: translateY(110vh) rotate(720deg);
                opacity: 0
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1> 活动抽奖 </h1>

        <!-- 速度滑条 -->
        <div class="speed-control">
            <h3>抽奖速度控制</h3>
            <div class="slider-container">
                <input type="range" id="speedSlider" min="1" max="10" value="5">
                <span id="speedValue">5</span>
            </div>
        </div>

        <!-- 九宫格 -->
        <div class="grid-container">
            <div class="grid-item"><div class="prize-icon">🎮</div><div class="prize-name">游戏主机</div><div class="prize-value">¥2999</div></div>
            <div class="grid-item"><div class="prize-icon">📱</div><div class="prize-name">智能手机</div><div class="prize-value">¥3999</div></div>
            <div class="grid-item"><div class="prize-icon">💻</div><div class="prize-name">笔记本电脑</div><div class="prize-value">¥5999</div></div>
            <div class="grid-item"><div class="prize-icon">🎧</div><div class="prize-name">无线耳机</div><div class="prize-value">¥899</div></div>
            <div class="grid-item"><div class="prize-icon">⌚</div><div class="prize-name">智能手表</div><div class="prize-value">¥1299</div></div>
            <div class="grid-item"><div class="prize-icon">🎁</div><div class="prize-name">神秘礼盒</div><div class="prize-value">¥1999</div></div>
            <div class="grid-item"><div class="prize-icon">🎫</div><div class="prize-name">优惠券</div><div class="prize-value">满1000减200</div></div>
            <div class="grid-item"><div class="prize-icon">🧧</div><div class="prize-name">现金红包</div><div class="prize-value">¥888</div></div>
            <div class="grid-item"><div class="prize-icon">🎨</div><div class="prize-name">画板套装</div><div class="prize-value">¥599</div></div>
        </div>

        <!-- 按钮 -->
        <div class="button-container">
            <button class="btn btn-start" id="startButton">开始抽奖</button>
            <button class="btn btn-stop" id="stopButton" disabled>停止抽奖</button>
            <button class="btn btn-reset" id="resetButton">重新开始</button>
        </div>

        <!-- 结果 -->
        <div class="result-container">
            <div class="result-title">🎉 抽奖结果 🎉</div>
            <div class="result-content" id="resultContent">
                <div class="result-icon">🎰</div>
                <div class="result-text">等待抽奖开始...</div>
            </div>
        </div>

        <!-- 抽奖记录（水平滚动） -->
        <div class="history">
            <h2>📜 抽奖记录</h2>
            <div class="history-list" id="historyList">
                <div class="history-item">
                    <div class="history-icon">📝</div>
                    <div class="history-name">暂无记录</div>
                    <div class="history-time">--:--:--</div>
                </div>
            </div>
        </div>
    </div>

    <script>
        /* === 基本数据 === */
        const prizes = [...document.querySelectorAll('.grid-item')].map(el => ({
            name: el.querySelector('.prize-name').textContent,
            value: el.querySelector('.prize-value').textContent,
            icon: el.querySelector('.prize-icon').textContent
        }));
        const gridItems = document.querySelectorAll('.grid-item');
        const startBtn = document.getElementById('startButton');
        const stopBtn = document.getElementById('stopButton');
        const resetBtn = document.getElementById('resetButton');
        const resultBox = document.getElementById('resultContent');
        const historyBox = document.getElementById('historyList');
        const speedSlider = document.getElementById('speedSlider');
        const speedValue = document.getElementById('speedValue');

        let isSpin = false, current = 0, win = -1, timer = null;
        let base = 50, factor = 5;
        speedSlider.addEventListener('input', e => { factor = +e.target.value; speedValue.textContent = factor });

        const speed = () => Math.max(10, base / factor);

        /* === 功能函数 === */
        function reset() {
            clearTimeout(timer); isSpin = false; current = 0; win = -1;
            gridItems.forEach(el => el.classList.remove('active', 'win'));
            resultBox.innerHTML = '<div class="result-icon">🎰</div><div class="result-text">等待抽奖开始...</div>';
            startBtn.disabled = false; stopBtn.disabled = true;
        }
        function start() {
            if (isSpin) return;
            reset(); isSpin = true; startBtn.disabled = true; stopBtn.disabled = false;
            win = Math.floor(Math.random() * 9);
            resultBox.innerHTML = '<div class="result-icon">🎡</div><div class="result-text">抽奖进行中...</div>';
            run();
        }
        function run() {
            gridItems.forEach(el => el.classList.remove('active'));
            gridItems[current].classList.add('active');
            current = (current + 1) % 9;
            if (current === win && Math.random() > .7) { setTimeout(end, 100); return }
            timer = setTimeout(run, speed());
        }
        function stopLottery() {
            if (!isSpin) return;
            clearTimeout(timer); isSpin = false;
            if (win < 0) win = Math.floor(Math.random() * 9);
            gridItems.forEach(el => el.classList.remove('active'));
            gridItems[win].classList.add('active', 'win');
            showResult();
            startBtn.disabled = false; stopBtn.disabled = true;
        }
        function end() { stopLottery() }
        function showResult() {
            const p = prizes[win];
            resultBox.innerHTML = `<div class="result-icon">${p.icon}</div><div class="result-text"><div class="result-name">${p.name}</div><div class="result-value">${p.value}</div></div>`;
            confetti(); addHistory(p);
        }
        function confetti() {
            const colors = ['#00f9ff', '#ff00a0', '#ffffff', '#00ffa2', '#ffea00'];
            for (let i = 0; i < 150; i++) {
                const c = document.createElement('div');
                c.className = 'confetti';
                c.style.left = Math.random() * 100 + 'vw';
                c.style.background = colors[Math.floor(Math.random() * colors.length)];
                c.style.width = c.style.height = Math.random() * 8 + 4 + 'px';
                document.body.appendChild(c);
                setTimeout(() => c.remove(), 3000);
            }
        }
        let history = [];
        function addHistory(p) {
            const t = new Date();
            history.unshift({ ...p, time: t.toLocaleTimeString() });
            if (history.length > 5) history.pop();
            updateHistory();
        }
        function updateHistory() {
            if (!history.length) {
                historyBox.innerHTML = '<div class="history-item"><div class="history-icon">📝</div><div class="history-name">暂无记录</div><div class="history-time">--:--:--</div></div>';
                return;
            }
            historyBox.innerHTML = '';
            history.forEach(h => {
                const d = document.createElement('div');
                d.className = 'history-item';
                d.innerHTML = `<div class="history-icon">${h.icon}</div><div class="history-name">${h.name}</div><div class="history-time">${h.time}</div>`;
                historyBox.appendChild(d);
            });
        }

        /* === 事件 === */
        startBtn.addEventListener('click', start);
        stopBtn.addEventListener('click', stopLottery);
        resetBtn.addEventListener('click', reset);
        reset(); updateHistory();
    </script>
</body>
</html>